package com.lsmo.android.carfans.activity.car;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.lsmo.android.carfans.model.car.Brand;

/**
 * 品牌
 * @author SYX
 */
public class BrandParser{
	
  public static final String TAG = "BrandParser";
  public static final String ALLSPELL = "AllSpell";
  public static final String ENAME = "EName";
  public static final String FIRSTLETTER = "FirstLetter";
  public static final String ID = "Id";
  public static final String IMAGE = "Image";
  public static final String MAXVALUE = "MaxValue";
  public static final String MINVALUE = "MinValue";
  public static final String NAME = "Name";
  public static final String REFERPRICERANGE = "ReferPriceRange";
  public String url = "";

  public BrandParser(String paramString)
  {
    this.url = paramString;
    Log.i(TAG,"this.url=" + url);
  }
  
  //将json字符串set到Brand中
  public static Brand build(JSONObject paramJSONObject)
  {
    Brand localBrand1 = new Brand();
    try
    {
      String str1 = paramJSONObject.getString("Name");
      localBrand1.setName(str1);
      
      int i = paramJSONObject.getInt("Id");
      localBrand1.setId(i);
      
      String str2 = paramJSONObject.getString("FirstLetter");
      localBrand1.setFirstLetter(str2);
      
      String str3 = paramJSONObject.getString("AllSpell");
      localBrand1.setAllSpell(str3);
      
      String str4 = paramJSONObject.getString("EName");
      localBrand1.setEName(str4);
      
      String str5 = paramJSONObject.getString("Image");
      localBrand1.setImage(str5);
      
      String str6 = paramJSONObject.getString("MinValue");
      localBrand1.setMinValue(str6);
      
      String str7 = paramJSONObject.getString("MaxValue");
      localBrand1.setMaxValue(str7);
      
      if (paramJSONObject.getString("ReferPriceRange").length() > 0)
      {
        String str8 = paramJSONObject.getString("ReferPriceRange");
        localBrand1.setReferPriceRange(str8);
      } else {
    	  localBrand1.setReferPriceRange("暂无");
      }
    }
    catch (JSONException localJSONException)
    {
      localJSONException.printStackTrace();
    }
    return localBrand1;
  }
  
  public ArrayList<Brand> Paser2Object()
  {
    ArrayList<Brand> localArrayList1 = new ArrayList();
    JSONArray localJSONArray = null;
    int j = 0;
    try
    {
      if (url != null)
      {
        String str1 = url;
        localJSONArray = new JSONArray(str1);
        int i = localJSONArray.length();
        if (localJSONArray != null && i > 0){
        	for(j=0;j<i;j++){
        		Brand brand = build(localJSONArray.getJSONObject(j));
                localArrayList1.add(brand);
        	}
    		
        }
      }
    }
    catch (JSONException localJSONException)
    {
    	localJSONException.printStackTrace();
    }
	return localArrayList1;
  }

}
